import Vue from 'vue'
import VueRouter from 'vue-router'
const Home = () =>
  import ('../components/Home.vue')

const About = () =>
  import ('../components/About.vue')
const Messages = () =>
  import ('../components/Messages.vue')
const News = () =>
  import ('../components/News.vue')
const Profile = () =>
  import ('../components/Profile.vue')

// import Home from '../components/Home.vue'
// import About from '../components/About.vue'
Vue.use(VueRouter) // 使用插件


const routes = [{
    path: '',
    redirect: '/home'
  }, {
    path: '/home',
    component: Home,
    children: [{
        path: '',
        redirect: 'message',

      },
      {
        path: 'message',
        component: Messages,
        meta: {
          'title': '首页'
        },
      },
      {
        path: 'news',
        component: News,
        meta: {
          'title': '首页'
        },
      }
    ]
  },
  {
    path: '/about',
    component: About,
    meta: {
      'title': '关于'
    }
  },
  {
    path: '/profile/:id',
    component: Profile,
    meta: {
      'title': '数据'
    }
  },
]



const router = new VueRouter({
  routes,
  mode: 'history',
  linkActiveClass: 'cuifan',
  linkExactActiveClass: 'jiamin'
})

// router.beforeEach((to, from, next) => {
//   window.document.title = to.meta.title
//   next()
// })

router.afterEach(route => {
  window.document.title = route.meta.title
})
export default router